// 引入express模块
const express = require('express')
// 引入连接池模块
const pool = require('../pool.js')
// 创建路由对象
const aill = express.Router()

// 历史分页数据查询接口
aill.get(('/select'), (req, res, next) => {
    console.log("小鱼id", req.query.classid)
    let classs = parseInt(req.query.classid)
    pool.query('select * from aill where classid=?', [classs], (err, result) => {
        if (err) {
            next(err)
            console.log(err.message)
            return
        }
        console.log(result)
    })
    let page = parseInt(req.query.page ? req.query.page : 1)
    let pagesize = 6
    // 从第几条开始
    let setye = (page - 1) * pagesize
    // 一共几条数据
    let rowcount
    pool.query('select count(id) as count from aill', (err, result) => {
        if (err) {
            next(err)
            return
        }
        console.log('打印', result)
        rowcount = result[0].count
        let pagecount = Math.ceil(rowcount / pagesize)
        sql = 'select * from aill where classid=? limit ?,?'
        pool.query(sql, [classs, setye, pagesize], (err, result) => {
            if (err) {
                next(err)
                return
            }
            console.log('结果', result),
                res.send({
                    code: 200,
                    msg: '查询成功',

                    result: result,
                    pagecount: pagecount,
                    page: page
                })
        })

    })
})
module.exports = aill